package com.example.a14110100420.yuejian.WAdapter.personal;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.a14110100420.yuejian.R;
import com.example.a14110100420.yuejian.WActivity.picture.PictureDetailActivity;
import com.example.a14110100420.yuejian.Wbase.BaseActivity;
import com.example.a14110100420.yuejian.Wbean.personal.ShowPictureList;
import com.example.a14110100420.yuejian.Wviewholder.personal.MyFatieListViewholder;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import static com.example.a14110100420.yuejian.R.id.username;

/**
 * Created by wanger on 2017/10/19.
 */

public class MyFatieListAdapter extends RecyclerView.Adapter {
    private Context context;
    private List<ShowPictureList> pictureList= new ArrayList<>();
    private LayoutInflater layoutInflater;
    public MyFatieListAdapter(Context context, List<ShowPictureList> pictureList){
        this.context = context;
        this.pictureList = pictureList;
        layoutInflater = LayoutInflater.from(context);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.myfatielist_adapter,parent,false);
        MyFatieListViewholder viewholder = new MyFatieListViewholder(itemView);
        return viewholder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MyFatieListViewholder myFatieListViewholder = (MyFatieListViewholder) holder;
        final ShowPictureList showPictureList =  pictureList.get(position);
        final String userid = BaseActivity.getUserid();
        String Username = BaseActivity.getUsername();
        final String shaituid = showPictureList.getId();
        final String fatieTupian = showPictureList.getThumb0();
        final String fatieTime = showPictureList.getUpdate_time();
        final String title = showPictureList.getTitle();
        final String userTouxiang = BaseActivity.getUsertouxiang();

        myFatieListViewholder.user_name.setText(Username);
        myFatieListViewholder.fatie_context.setText(title);
        myFatieListViewholder.fatie_time.setText(fatieTime);
        Picasso.with(context)
                .load("http://172.24.10.175/workout/Uploads/"+userTouxiang)
                .into(myFatieListViewholder.touxiang);
        Picasso.with(context)
                .load("http://172.24.10.175/workout/Uploads/"+fatieTupian)
                .into(myFatieListViewholder.fatie_tupian);

        if(myFatieListViewholder.fatie_tupian.getDrawable()==null){
            myFatieListViewholder.fatie_tupian.setImageResource(R.drawable.kobe2);
        }
        myFatieListViewholder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, PictureDetailActivity.class);
                intent.putExtra("shaitu_id",shaituid);
                intent.putExtra("fatie_detail",title);
                intent.putExtra("user_name",username);
                intent.putExtra("fatiepic",fatieTupian);
                intent.putExtra("userpic",userTouxiang);
                intent.putExtra("fatie_time",fatieTime);
                intent.putExtra("userid",userid);
                context.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return pictureList.size();
    }
}
